#!/usr/bin/perl
#pvrescan
require './lvm-lib.pl';
&ReadParse();
my ($err_msg, $vgname, @pvinfo, @vginfo, @lvinfo, $v, $vg, $lock);

$err_msg="";
@pvinfo = get_pv_info();
@vginfo = get_vg_info();
@lvinfo = get_lv_info();
$vgname = $in{'vg'};
if (!$vgname){
	$err_msg=$text{'noselectvg'};
	goto ERROR_OUT;
}

my $found = 0;
foreach $v (@vginfo) {
	if ($v->{'vg'} eq $vgname) {
		$vg = $v;
		$found = 1;
		last;
	}
}

if (!$found) {
	$err_msg = $text{'err_vgnofound'};
	goto ERROR_OUT;
}
&header($text{'title_vginfo'}, "", "vgdetail", 0, 1);
#goto ERROR_OUT;
my @vg_pvs = get_pvs_of_vg($vg, @pvinfo);
my $vgpv;
my @vg_lvs = get_lvs_of_vg($vg, @lvinfo);
my $vglv;
print "<table class=group border=1 cellpadding=4 cellspacing=0 width=100%>\n";
print "<tr class=title1><td class=group><b>$text{'title_vginfo'}</b></td></tr>\n";
print "<tr><td class=group><table class=mode1 cellpadding=3 cellspacing=0 width=100%>\n";
print "<tr><td width=250><b>$text{'index_vg'}</b></td><td>$vg->{'vg'}</td></tr>\n";
#print "<tr><td width=250><b>$text{'index_vg_status'}</b></td><td>$vg->{'status'}</td></tr>\n";
print "<tr><td width=250><b>$text{'index_vg_pvnum'}</b></td><td>";
foreach $vgpv (@vg_pvs) {
	print $vgpv.", ";
}
print "Total: ".$vg->{'pvnum'};	
print "</td></tr>\n";
print "<tr><td width=250><b>$text{'index_vg_lvnum'}</b></td><td>";
foreach $vglv (@vg_lvs) {
	print "<b>".$vglv->{'lvname'}."</b>, ";
}
print "Total: ".$vg->{'lvnum'};
print "</td></tr>\n";
print "<tr><td width=250><b>$text{'index_vg_size'}</b></td><td>$vg->{'size'}</td></tr>\n";
print "<tr><td width=250><b>$text{'index_vg_free'}</b></td><td>$vg->{'free'}</td></tr>\n";
my $perc = (1 - $vg->{'free'} / $vg->{'size'}) * 100;
print "<tr><td width=250></td><td><table border=0 width=400 height=10 cellspacing=0><tr>";
my $j = 0;
my $vl;
foreach $vl (@vg_lvs) {
	$perc = $vl->{'size'} / $vg->{'size'} * 100;
	if ($perc < 1) {
		$percv= "1%";
	}
	else{
		$percv = $perc."%";
	}
	if($j % 2 == 0){
		print "<td width=$percv bgcolor=jaune title=$vl->{'lvname'}> </td>";
	}
	else{
		print "<td width=$percv bgcolor=lime title=$vl->{'lvname'}> </td>";
	}
	$j++;
}
print "<td width=* bgcolor='#C0C0C0' title=FreeSpace:$vg->{'free'}MB></td>";
print "</td>";
print "</tr></table></td></tr>";
print "</table></td></tr>\n";
print "</table>\n";


&footer("/lvm/", $text{'index'});
return;
ERROR_OUT:
&error_setup($text{'crt_err_title'});
&error($err_msg);
